﻿function Create_New_Task() {
    var indexTasks = parseInt($("#tasks_count").val());
    var tasksLayer = '<table id="t_' + indexTasks + '" style="width:100%;background-color:#F0F0F0;padding-top:10px;margin-top:5px">';
    tasksLayer += '<tr><td rowspan="5" style="padding-left:40px;width:10%;"><img style="cursor:pointer" onclick="Create_New_Task()" src="/Static/img/itask/add_icon.png" /><img style="cursor:pointer" onclick="Del_Task(' + indexTasks + ')" src="/Static/img/itask/delete_icon.png" /></td>';
    tasksLayer += '<td class="tdleft"><font color="red">*</font>任务名称：</td><td colspan="5"><input  id="txt_task_name_' + indexTasks + '" class="mini-textbox" maxlength="50" required="true" style="width:97.3%" required="true" /></td></tr>';
    tasksLayer += '<tr><td class="tdleft"><font color="red">*</font>类别：</td><td><input style="width: 90%" id="txt_category_id_' + indexTasks + '" class="mini-buttonedit" onbuttonclick="onSelectTaskType" allowinput="false" required="true" /></td><td class="tdleft"><font color="red">*</font>下达人：</td><td><input style="width: 90%" id="txt_assign_user_name_' + indexTasks + '" class="mini-buttonedit" readonly="readonly" /></td><td class="tdleft"><font color="red">*</font>负责人：</td><td><input style="width: 90%" id="txt_manage_user_name_' + indexTasks + '" class="mini-buttonedit" onbuttonclick="onSelectUser" allowinput="false" required="true" /></td></tr>';
    tasksLayer += '<tr><td class="tdleft"><font color="red">*</font>开始时间：</td><td><input style="width: 90%" id="txt_estimated_start_time_' + indexTasks + '" class="mini-datepicker" required="true" /></td><td class="tdleft"><font color="red">*</font>结束时间：</td><td><input style="width: 90%" id="txt_estimated_end_time_' + indexTasks + '" class="mini-datepicker" required="true" /></td><td class="tdleft">任务属性：</td><td><div style="width: 90%" id="txt_task_property_' + indexTasks + '" class="mini-combobox"  textField="name_" valueField="category_id_"  url="/AJAX/AjaxService.aspx?method=GetTaskTypeList&option_=2" multiSelect="true"  showClose="true" oncloseclick="onCloseClick" ><div property="columns"><div header="任务属性" field="name_"></div></div></div></td></tr>';
    tasksLayer += '<tr><td class="tdleft">抄送人：</td><td colspan="5"><input id="txt_cc_' + indexTasks + '" class="mini-buttonedit" onbuttonclick="onSelectUserMul" allowinput="false" style="width: 97.3%;" /></td></tr>';
    tasksLayer += '<tr><td class="tdleft"><font color="red">*</font>任务目标：</td><td colspan="5"><input id="txt_description_' + indexTasks + '" style="width: 97.3%;height:80px" class="mini-textarea" maxlength="8000" required="true"/></td></tr>';
    tasksLayer += '</table>';
    $('#d_tasks').append(tasksLayer);


    $('#tasks_count').val(parseInt($('#tasks_count').val()) + 1);
    mini.parse();

    mini.get("txt_assign_user_name_" + indexTasks).setValue(mini.get("txt_assign_user_name_0").getValue());
    mini.get("txt_assign_user_name_" + indexTasks).setText(mini.get("txt_assign_user_name_0").getText());
    mini.get("txt_manage_user_name_" + indexTasks).setValue(mini.get("txt_manage_user_name_0").getValue());
    mini.get("txt_manage_user_name_" + indexTasks).setText(mini.get("txt_manage_user_name_0").getText());

}
function Del_Task(id) {
    $("#t_" + id).remove();
}
function saveData() {
    var form = new mini.Form("#form1");
    form.validate();
    if (form.isValid() == false) return; //表单证验
    var tasks = parseInt($("#tasks_count").val());

    var taskNameArr = [];
    var categoryIDArr = [];
    var assignUserIDArr = [];
    var assignUserNameArr = [];
    var manageUserIDArr = [];
    var manageUserNameArr = [];
    var estimatedStartTimeArr = [];
    var estimatedEndTimeArr = [];
    var taskPropertyArr = [];
    var ccArr = [];
    var ccNameArr = [];
    var descriptionArr = [];

    for (var i = 0; i < tasks; i++) {
        var taskTable = document.getElementById("t_" + i); //$("#t_" + i);
        if (taskTable != null && taskTable != undefined) {
            //alert(taskTable);
            taskNameArr.push(mini.get("txt_task_name_" + i).getValue());
            categoryIDArr.push(mini.get("txt_category_id_" + i).getValue());
            assignUserIDArr.push(mini.get("txt_assign_user_name_" + i).getValue());
            assignUserNameArr.push(mini.get("txt_assign_user_name_" + i).getText());
            manageUserIDArr.push(mini.get("txt_manage_user_name_" + i).getValue());
            manageUserNameArr.push(mini.get("txt_manage_user_name_" + i).getText());
            estimatedStartTimeArr.push(mini.get("txt_estimated_start_time_" + i).getText());
            estimatedEndTimeArr.push(mini.get("txt_estimated_end_time_" + i).getText());
            taskPropertyArr.push(mini.get("txt_task_property_" + i).getValue());
            ccArr.push(mini.get("txt_cc_" + i).getValue());
            ccNameArr.push(mini.get("txt_cc_" + i).getText());
            descriptionArr.push(mini.get("txt_description_" + i).getValue());
        }
    }
    $.ajax({
        url: "/AJAX/AjaxService.aspx?method=StartTask",
        type: "post",
        cache: false,
        data: {
            task_name_: taskNameArr,
            category_id_: categoryIDArr,
            assign_user_id_: assignUserIDArr,
            assign_user_name_: assignUserNameArr,
            manage_user_id_: manageUserIDArr,
            manage_user_name_: manageUserNameArr,
            estimated_start_time_: estimatedStartTimeArr,
            estimated_end_time_: estimatedEndTimeArr,
            task_property_: taskPropertyArr,
            meeting_id_: getUrlParam("meeting_id_"),
            cc_: ccArr,
            cc_name_: ccNameArr,
            description_: descriptionArr
        },
        success: function (text) {
            window.top.location.href = "/iTask/MyAssign/MyAssignList.aspx";
        },
        error: function (jqXHR, textStatus, errorThrown) {

        }
    });
}
